<template>
  <basic-container>
    <avue-crud :option="option" :table-loading="loading" :data="data" ref="crud" v-model="form" @row-del="rowDel" @row-update="rowUpdate" @row-save="rowSave" :before-open="beforeOpen" @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange" @refresh-change="refreshChange" @on-load="onLoad" :span-method="spanMethod">
      <template slot="menuRight">
        <table-right :crud='$refs.crud' :data='data' :searchBtn="false" :columnBtn="true" :addPermission="!isHaveControlplan" :handleDelete="handleDelete" :delPermission="false" :refreshChange='refreshChange'>
          <!-- <el-button type="text" icon="el-icon-s-promotion" v-if="submitBtn" @click="handleSubmit">提交</el-button> -->
        </table-right>
      </template>
      <template slot-scope="{row}" slot="controlPlanNo"><span style="font-weight:700;text-align:center">{{row.controlPlanNo}}</span></template>
      <template slot-scope="{row}" slot='chargeId'>{{row.chargeName}}
      </template>
      <template slot-scope="{row}" slot='coreGroup'>{{row.coreGroupName}}
      </template>
      <template slot-scope="{row}" slot='standard'>
        <span v-if="row.standardType=='1'">{{row.standard}}</span>
        <el-image v-else style="width: 40px; height: 40px" :src="row.standard" :preview-src-list="[row.standard]">
        </el-image>
      </template>
      <template slot-scope="{row}" slot="menu">
        <el-tooltip class="item" effect="dark" content="查看" placement="bottom">
          <el-button icon="el-icon-view" size="small" type="text" @click.stop="$refs.crud.rowView(row,row.$index)" v-if="viewBtn"></el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="编辑" placement="bottom">
          <el-button icon="el-icon-edit" size="small" :disabled="row.controlPlanStatus==2||row.controlPlanStatus==3" type="text" @click.stop="$refs.crud.rowEdit(row,row.$index)" v-if="row.createUser==userId&&editBtn"></el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="删除" placement="bottom">
          <el-button icon="el-icon-delete" size="small" :disabled="row.controlPlanStatus==2||row.controlPlanStatus==3" type="text" @click.stop="rowDel(row)" v-if="row.createUser==userId&&delBtn"></el-button>
        </el-tooltip>
        <!-- <el-tooltip content="跟踪" style="height:auto" effect="dark" class="rightbtn" placement="bottom" v-if="row.createUser==userId&&permission.projectcontrol_controlplan_track">
          <div class="top-bar__item">
            <el-button type="text" size="small" :disabled="row.controlPlanStatus == 1" icon="el-icon-share" @click.stop="handleImage(row)"></el-button>
          </div>
        </el-tooltip> -->
      </template>
      <template slot="stage" slot-scope="{row}">{{row.stageName}}</template>
      <template slot="infoForm" slot-scope="scope">
        <avue-crud class='scopeCrud' :table-loading="scopeloading" ref="scopeCrud" :page='false' :option="option2" :data="scopeData" v-model="scopeForm" :span-method="spanScopeMethod">
          <template slot-scope="{row}" slot='standard'>
            <span v-if="row.standardType=='1'">{{row.standard}}</span>
            <el-image v-else style="width: 40px; height: 40px" :src="row.standard" :preview-src-list="[row.standard]">
            </el-image>
          </template>
        </avue-crud>
      </template>
    </avue-crud>
    <!-- <el-dialog title="流程图" :visible.sync="flowBox" width="80%" append-to-body='true'>
      <img :src="flowUrl" width="100%" />
      <span slot="footer" class="dialog-footer">
        <el-button @click="flowBox = false">关 闭</el-button>
      </span>
    </el-dialog> -->
  </basic-container>
</template>
<script>
// import {
//   getAllMembers,
//   getNewestControlplan,
//   removeControlplan,
//   getDetailPlans,
//   updateControlplan,
// } from '@/api/projectcontrol/controlplan';
// import { getNewFmea } from '@/api/projectcontrol/fmea';

import { mapGetters } from 'vuex';
import { init } from '@/mixins/init';
import { getBusinessList } from '@/api/zidian';
export default {
  mixins: [init],
  components: {},
  props: {
    addBtn: {
      type: Boolean,
    },
    viewBtn: {
      type: Boolean,
    },
    editBtn: {
      type: Boolean,
    },
    delBtn: {
      type: Boolean,
    },
    submitBtn: {
      type: Boolean,
    },
    productId: {
      type: String,
    },
    materialName: {
      type: String,
    },
    innerDrawingNo: {
      type: String,
    },
    materialNo: {
      type: String,
    },
    type: {
      type: String,
    },
  },
  data() {
    return {
      debounce: true,
      isDetail: 1,
      flowBox: false,
      flowUrl: '',
      personId: '', //当前用户对应的人员id
      // productList: [], //产品list
      documentList: [], //apqp模板文件list
      stageList: [],
      problemList: [],
      isHaveControlplan: false,
      option: {
        // height: 'auto',
        size: 'mini',
        page: false,
        dialogHeight: '100%',
        dialogWidth: '100%',
        tip: false,
        border: true,
        index: false,
        indexLabel: '序号',
        selection: true,
        viewBtn: false,
        delBtn: false,
        editBtn: false,
        addBtn: false,
        menuWidth: 90,
        columnBtn: true,
        filterBtn: true,
        searchMenuSpan: 12,
        dialogClickModal: false,
        labelWidth: 110,
        defaultExpandAll: true,
        column: [
          {
            label: '计划编号',
            prop: 'controlPlanNo',
            slot: true,
            span: 12,
            maxlength: 15,
            rules: [
              {
                required: true,
                message: '请输入计划编号',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '产品',
            prop: 'productId',
            hide: true,
            showColumn: false,
            disabled: true,
            type: 'select',
            dicData: [],
            props: {
              label: 'label',
              value: 'id',
            },
            rules: [
              {
                required: true,
                message: '请选择产品',
                trigger: 'blur',
              },
            ],
            span: 12,
            minWidth: 130,
            filterable: true,
            change: (val) => {
              if (val.value) {
                // this.productList.map((item) => {
                //   if (item.id == val.value) {
                //     this.form.innerDrawingNo = item.innerDrawingNo;
                //     this.form.materialNo = item.materialNo;
                //   }
                // });
                if (this.formType == 'add') {
                  this.scopeloading = true;
                  getDetailPlans(val.value)
                    .then((res) => {
                      if (res.data.success) {
                        this.scopeloading = false;
                        var list = res.data.data.detailVOS;
                        list.map((item) => {
                          item.$cellEdit = true;
                        });
                        this.scopeData = list;
                        this.addScopeSpanNumber();
                      }
                    })
                    .catch((err) => {
                      this.scopeloading = false;
                      this.scopeData.length = 0;
                      this.scopeData = [];
                    });
                }
              }
            },
          },
          {
            label: '产品阶段',
            prop: 'stage',
            hide: true,
            showColumn: false,
            span: 12,
            overHidden: true,
            slot: true,
            type: 'checkbox',
            dicUrl: '/api/blade-system/dict-biz/dictionary?code=product_stage',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
            rules: [
              {
                required: true,
                message: '请选择产品阶段',
                trigger: 'change',
              },
            ],
          },
          {
            label: '主要联系人',
            prop: 'chargeId',
            span: 12,
            hide: true,
            showColumn: false,
            overHidden: true,
            slot: true,
            type: 'select',
            dicData: [],
            props: {
              label: 'name',
              value: 'id',
            },
            rules: [
              {
                required: true,
                message: '请选择主要联系人',
                trigger: 'change',
              },
            ],
          },
          {
            label: '产品图号',
            prop: 'innerDrawingNo',
            span: 12,
            hide: true,
            showColumn: false,
            disabled: true,
          },
          {
            label: '产品编号',
            prop: 'materialNo',
            span: 12,
            hide: true,
            showColumn: false,
            disabled: true,
          },
          {
            label: '编制日期',
            prop: 'createDate',
            hide: true,
            showColumn: false,
            type: 'date',
            valueFormat: 'yyyy-MM-dd',
            span: 12,
            width: 100,
            rules: [
              {
                required: true,
                message: '请选择编制日期',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '最后修订日期',
            prop: 'finalUpdateDate',
            hide: true,
            showColumn: false,
            type: 'date',
            valueFormat: 'yyyy-MM-dd',
            span: 12,
            width: 100,
          },
          {
            label: '项目小组',
            prop: 'coreGroup',
            span: 12,
            minWidth: 100,
            hide: true,
            showColumn: false,
            slot: true,
            type: 'select',
            multiple: true,
            dicData: [],
            props: {
              label: 'name',
              value: 'id',
            },
            rules: [
              {
                required: true,
                message: '请选择项目小组',
                trigger: 'change',
              },
            ],
          },
          {
            label: 'PFMEA编号',
            prop: 'fmeaPlanNo',
            disabled: true,
            span: 12,
            hide: true,
            showColumn: false,
          },
          {
            label: '步骤序号',
            prop: 'processNo',
            align: 'left',
            display: false,
            hide: false,
            maxlength: 5,
            disabled: true,
            rules: [
              {
                required: true,
                message: '请输入步骤序号',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '工序名称',
            prop: 'processName',
            display: false,
            hide: false,
            disabled: true,
            minWidth: 120,
          },
          {
            label: '生产设备',
            prop: 'equipmentName',
            display: false,
            overHidden: true,
          },
          {
            label: '特性',
            align: 'center',
            children: [
              {
                label: '产品',
                prop: 'productFeature',
                display: false,
                span: 24,
                overHidden: true,
                maxlength: 30,
              },
              {
                label: '过程',
                prop: 'procedureFeature',
                display: false,
                span: 24,
                overHidden: true,
                maxlength: 30,
              },
            ],
          },
          {
            label: '特殊特性分类',
            prop: 'quaType',
            width: 80,
            align: 'center',
            overHidden: true,
            display: false,
            span: 24,
            type: 'select',
            dicUrl: '/api/blade-system/dict-biz/dictionary?code=featureType',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
            rules: [
              {
                required: true,
                message: '请选择特殊特性分类',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '方法',
            align: 'center',
            children: [
              {
                label: '规范/公差',
                prop: 'standard',
                display: false,
                slot: true,
                span: 24,
                overHidden: true,
              },
              {
                label: '测量技术',
                prop: 'checkToolName',
                display: false,
                span: 24,
                overHidden: true,
              },
              {
                label: '样品',
                align: 'center',
                children: [
                  {
                    label: '容量',
                    prop: 'capacity',
                    overHidden: true,
                    maxlength: 20,
                    display: false,
                  },
                  {
                    label: '频率',
                    prop: 'frequency',
                    overHidden: true,
                    maxlength: 20,
                    display: false,
                  },
                ],
              },
              {
                label: '控制方法',
                prop: 'method',
                span: 24,
                overHidden: true,
                display: false,
              },
              {
                label: '责任人',
                prop: 'responsible',
                type: 'select',
                dicUrl: '/api/blade-system/dict-biz/dictionary?code=chargerInControlplan',
                props: {
                  label: 'dictValue',
                  value: 'dictKey',
                },
                span: 24,
                display: false,
                overHidden: true,
              },
            ],
          },
          {
            label: '反应计划',
            prop: 'responsePlan',
            display: false,
            hide: true,
            showColumn: false,
            span: 24,
            overHidden: true,
          },
          {
            label: '批准日期',
            prop: 'gfApprovalDate',
            hide: true,
            showColumn: false,
            display: false,
            type: 'date',
            valueFormat: 'yyyy-MM-dd',
            span: 12,
            width: 100,
          },
          {
            labelPosition: 'top',
            prop: 'info',
            span: 24,
            formslot: true,
            hide: true,
            showColumn: false,
          },
          {
            label: '状态',
            prop: 'controlPlanStatus',
            span: 12,
            width: 60,
            display: false,
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=special_status',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
          },
        ],
      },
      data: [],
      formData: {},
      goon: false,
      formType: 'add',
      form: {
        stage: [],
      },
      scopeloading: false,
      option2: {
        dialogModal: true,
        menu: false,
        selection: false,
        editBtn: true,
        viewBtn: true,
        delBtn: false,
        index: true,
        tip: false,
        header: false,
        column: [
          {
            label: '步骤序号',
            prop: 'processNo',
            width: 80,
          },
          {
            label: '工序名称',
            prop: 'processName',
          },
          { label: '生产设备', prop: 'equipmentName' },
          {
            label: '特性',
            align: 'center',
            children: [
              {
                label: '产品',
                prop: 'productFeature',
                span: 24,
                minWidth: 150,
                overHidden: true,
                maxlength: 30,
              },
              {
                label: '过程',
                prop: 'procedureFeature',
                span: 24,
                minWidth: 150,
                overHidden: true,
                maxlength: 30,
              },
            ],
          },
          {
            label: '特殊特性分类',
            prop: 'quaTypeName',
            align: 'center',
            overHidden: true,
            width: 50,
            span: 24,
          },
          {
            label: '方法',
            align: 'center',
            children: [
              {
                label: '规范/公差',
                prop: 'standard',
                slot: true,
                span: 24,
                minWidth: 150,
                overHidden: true,
              },
              {
                label: '测量技术',
                prop: 'checkToolName',
                span: 24,
                minWidth: 150,
                // overHidden: true,
              },
              {
                label: '样品',
                align: 'center',
                children: [
                  {
                    label: '容量',
                    prop: 'capacity',
                    minWidth: 150,
                    maxlength: 20,
                  },
                  {
                    label: '频率',
                    prop: 'frequency',
                    minWidth: 150,
                    maxlength: 20,
                  },
                ],
              },
              {
                label: '控制方法',
                prop: 'method',
                span: 24,
                minWidth: 170,
                overHidden: true,
                maxlength: 30,
                cell: true,
              },
              {
                label: '责任人',
                prop: 'responsible',
                type: 'select',
                dicUrl: '/api/blade-system/dict-biz/dictionary?code=chargerInControlplan',
                props: {
                  label: 'dictValue',
                  value: 'dictKey',
                },
                span: 24,
                minWidth: 110,
                overHidden: true,
                cell: true,
              },
            ],
          },
          {
            label: '反应计划',
            prop: 'responsePlan',
            span: 24,
            minWidth: 170,
            overHidden: true,
            maxlength: 30,
            cell: true,
          },
        ],
      },
      scopeData: [],
    };
  },
  watch: {
    // productId(newVal) {
    //   this.productList.every((item) => {
    //     if (item.id == newVal) {
    //       this.searchProductCode = item.materialNo;
    //       return false;
    //     } else {
    //       return true;
    //     }
    //   });
    // },
    'form.productId'(val, oldVal) {
      if (val) {
        getAllMembers({ productId: val }).then((res) => {
          const data = res.data.data;
          this.findObject(this.option.column, 'chargeId').dicData = data;
          this.findObject(this.option.column, 'coreGroup').dicData = data;
        });
      }
    },
    productAndStage(val, oldVal) {
      if (!this.debounce) {
        this.debounceFn(val);
      }
    },
  },
  computed: {
    ...mapGetters(['userId', 'permission']),
    productAndStage() {
      return { productId: this.form.productId, stage: this.form.stage };
    },
  },
  created() {
    if (this.type == 'edit') {
      this.option.header = true;
      this.option.menu = true;
    } else {
      this.option.header = false;
      this.option.menu = false;
    }
    this.findObject(this.option.column, 'productId').dicData = [
      { label: this.materialName + '（' + this.innerDrawingNo + '）', id: this.productId },
    ];
    getBusinessList('product_stage').then((res) => {
      this.stageList = res.data.data;
    });
    this.onLoad();
  },
  methods: {
    debounceFn(val) {
      if (val.productId && val.stage && val.stage.length > 0) {
        let stageList = [...val.stage];
        let stage = stageList.sort().join(',');
        getNewFmea({ productId: val.productId, stage: stage, status: '3' }).then((res) => {
          if (res.data.success) {
            const data = res.data.data;
            if (data.length == 0) {
              this.form.fmeaId = '';
              this.form.fmeaPlanNo = '';
              if (this.formType != 'view') {
                this.$message.warning('暂无所选产品阶段内的已审批PFMEA计划');
              }
            } else {
              this.form.fmeaId = data[0].id;
              this.form.fmeaPlanNo = data[0].fmeaPlanNo + '(' + data[0].finalUpdateDate + ')';
            }
            this.debounce = false;
          }
        });
      }
    },
    spanMethod({ row, column, rowIndex, columnIndex }) {
      if (this.isDetail == 1) {
        if (
          columnIndex === 0 ||
          columnIndex === 1 ||
          columnIndex === 2 ||
          columnIndex === 3 ||
          columnIndex === 4 ||
          columnIndex === 14 ||
          columnIndex === 16
        ) {
          if (row.noSpan) {
            return {
              rowspan: row.noSpan,
              colspan: 1,
            };
          } else {
            return {
              rowspan: 0,
              colspan: 0,
            };
          }
        }
        if (columnIndex === 5 || columnIndex === 6 || columnIndex === 7) {
          if (row.processSpan) {
            return {
              rowspan: row.processSpan,
              colspan: 1,
            };
          } else {
            return {
              rowspan: 0,
              colspan: 0,
            };
          }
        }
        // 窜行？？？？
        if (columnIndex === 8 || columnIndex === 9 || columnIndex === 10) {
          if (row.featureSpan) {
            return {
              rowspan: row.featureSpan,
              colspan: 1,
            };
          } else {
            return {
              rowspan: 0,
              colspan: 0,
            };
          }
        }
      } else {
      }
    },
    addSpanNumber() {
      const KEY_NAME = 'controlPlanNo';
      const KEY_NAME1 = 'processNo'; //步骤序号
      const KEY_NAME2 = 'procedureId'; //工序id
      const KEY_NAME3 = 'productFeatureId'; //产品特性Id
      const KEY_ROWSPAN = 'noSpan';
      const KEY_ROWSPAN1 = 'processSpan';
      const KEY_ROWSPAN3 = 'featureSpan';
      var k = 0;
      while (k < this.data.length) {
        this.data[k][KEY_ROWSPAN] = 1;
        this.data[k][KEY_ROWSPAN1] = 1;
        for (var i = k + 1; i <= this.data.length - 1; i++) {
          if (this.data[k][KEY_NAME] === this.data[i][KEY_NAME] && this.data[k][KEY_NAME] !== '') {
            this.data[k][KEY_ROWSPAN]++;
          } else {
            break;
          }
        }
        k = i;
      }
      var l = 0;
      while (l < this.data.length) {
        this.data[l][KEY_ROWSPAN1] = 1;
        for (var i = l + 1; i <= this.data.length - 1; i++) {
          const isSameProduct = this.data[l].productNo === this.data[i].productNo && this.data[l].productNo !== '';
          if (isSameProduct && this.data[l][KEY_NAME1] === this.data[i][KEY_NAME1] && this.data[l][KEY_NAME1] !== '') {
            this.data[l][KEY_ROWSPAN1]++;
          } else {
            break;
          }
        }
        l = i;
      }
      var m = 0;
      while (m < this.data.length) {
        this.data[m][KEY_ROWSPAN3] = 1;
        for (var i = m + 1; i <= this.data.length - 1; i++) {
          if (
            this.data[m][KEY_NAME1] === this.data[i][KEY_NAME1] &&
            this.data[m][KEY_NAME1] !== '' &&
            this.data[m][KEY_NAME2] === this.data[i][KEY_NAME2] &&
            this.data[m][KEY_NAME2] !== '' &&
            this.data[m][KEY_NAME3] === this.data[i][KEY_NAME3] &&
            this.data[m][KEY_NAME3] !== ''
          ) {
            this.data[m][KEY_ROWSPAN3]++;
          } else {
            break;
          }
        }
        m = i;
      }
    },
    spanScopeMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 1 || columnIndex === 2 || columnIndex === 3) {
        if (row.itemSpan) {
          return {
            rowspan: row.itemSpan,
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
      if (columnIndex === 4 || columnIndex === 5 || columnIndex === 6) {
        if (row.featureSpan) {
          return {
            rowspan: row.featureSpan,
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },
    addScopeSpanNumber() {
      const KEY_NAME = 'processNo';
      const KEY_ROWSPAN = 'itemSpan';
      const KEY_NAME1 = 'productFeatureId'; //产品特性Id
      const KEY_ROWSPAN1 = 'featureSpan';
      var k = 0;
      while (k < this.scopeData.length) {
        this.scopeData[k][KEY_ROWSPAN] = 1;
        for (var i = k + 1; i <= this.scopeData.length - 1; i++) {
          if (this.scopeData[k][KEY_NAME] === this.scopeData[i][KEY_NAME] && this.scopeData[k][KEY_NAME] !== '') {
            this.scopeData[k][KEY_ROWSPAN]++;
          } else {
            break;
          }
        }
        k = i;
      }
      var m = 0;
      while (m < this.scopeData.length) {
        this.scopeData[m][KEY_ROWSPAN1] = 1;
        for (var i = m + 1; i <= this.scopeData.length - 1; i++) {
          if (
            this.scopeData[m][KEY_NAME] === this.scopeData[i][KEY_NAME] &&
            this.scopeData[m][KEY_NAME] !== '' &&
            this.scopeData[m][KEY_NAME1] === this.scopeData[i][KEY_NAME1] &&
            this.scopeData[m][KEY_NAME1] !== ''
          ) {
            this.scopeData[m][KEY_ROWSPAN1]++;
          } else {
            break;
          }
        }
        m = i;
      }
    },

    validPlans(data) {
      let equipMsg = '';
      if (data.length > 0) {
        data.every((item, index) => {
          if (item.method == '') {
            equipMsg = `【控制计划明细】第${index + 1}行 请输入控制方法`;
            this.$message.error(equipMsg);
            return false;
          } else if (item.responsePlan == '') {
            equipMsg = `【控制计划明细】第${index + 1}行 请输入反应方法`;
            this.$message.error(equipMsg);
            return false;
          } else {
            return true;
          }
        });
        if (equipMsg) {
          return false;
        }
      }
      return true;
    },
    rowSave(row, done, loading) {
      let valid = this.validPlans(this.scopeData);
      if (!valid) {
        loading();
        return;
      }
      if (row.id == -1) {
        row.id = '';
        row.status = '';
      }
      row.coreGroup = row.coreGroup.join(',');
      row.stage = row.stage.join(',');
      row.detailVOS = this.scopeData;
      updateControlplan(row).then(
        () => {
          this.onLoad();
          done();
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
        },
        (error) => {
          this.goon = false;
          loading();
        }
      );
    },
    beforeOpen(done, type) {
      this.formType = type;
      if (['edit', 'view'].includes(type)) {
        this.debounce = true;
        this.scopeData = [];
        this.scopeloading = true;
        getDetailPlans(this.productId, this.form.controlPlanId).then((res) => {
          this.scopeloading = false;
          var list = res.data.data.detailVOS;
          if (type == 'edit') {
            list.map((item) => {
              item.$cellEdit = true;
            });
          }
          this.scopeData = list;
          this.addScopeSpanNumber();
          this.form = res.data.data;
          this.form.coreGroup = res.data.data.coreGroup.split(',');
          this.form.stage = res.data.data.stage.split(',');
          setTimeout(() => {
            this.debounceFn({ productId: this.form.productId, stage: this.form.stage });
          }, 500);
        });
      } else {
        this.scopeData.length = 0;
        this.$set(this.form, 'productId', this.productId);
        this.$set(this.form, 'innerDrawingNo', this.innerDrawingNo);
        this.$set(this.form, 'materialNo', this.materialNo);
        this.debounce = false;
      }
      done();
    },
    rowUpdate(row, index, done, loading) {
      let valid = this.validPlans(row);
      if (!valid) {
        loading();
        return;
      }
      row.stage = row.stage.join(',');
      row.coreGroup = row.coreGroup.join(',');
      row.detailVOS = this.scopeData;
      updateControlplan(row).then(
        () => {
          this.onLoad();
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          done();
        },
        (error) => {
          window.console.log(error);
          loading();
        }
      );
    },
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        if (row.id) {
          removeControlplan(row.controlPlanId).then((req) => {
            if (req.data.success) {
              this.$message.success('操作成功');
              this.onLoad();
            }
          });
        }
      });
    },
    onLoad(page, params = {}) {
      this.loading = true;
      this.query.productId = this.productId;
      getNewestControlplan(Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.data = data;
        if (data.length == 0) {
          this.isHaveControlplan = false;
        } else {
          this.isHaveControlplan = true;
        }
        this.loading = false;
        this.addSpanNumber();
        this.selectionClear();
      });
    },
  },
};
</script>
<style lang="scss">
.el-table--border th {
  border-bottom: 1px solid #d2dde9;
}
</style>
